package com.jdbc.login.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.jdbc.login.entity.StudentInfo;
@Repository
public class LoginDaoImpl implements LoginDao {
	
	@Resource
	public JdbcTemplate jtl;
	@Override
	public StudentInfo login(String username, String password) {
		RowMapper<StudentInfo> rowMapper = new RowMapper<StudentInfo>(){
			public StudentInfo mapRow(ResultSet res,int rowNum) throws SQLException{
				StudentInfo info = new StudentInfo();
				info.setSutdentId(res.getString(1));
				info.setUsername(res.getString(2));
				info.setPassword(res.getString(3));
				return info;
			}
		};
		String sql = "select * from student_info where student_name=? and student_pwd=? ";
		List<StudentInfo> list = jtl.query(sql, new Object[]{username,password},rowMapper);
		if(list.size()>0){
			return list.get(0);
		}else{
			return null;
		}
	}

}
